home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / turbo-tcp-20b4-cpp.hqx / TurboTCP / TurboTCP source / CTCPResolverCall.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-03  |  5.1 KB  |  162 lines

  1. /*
  2. ** CTCPResolverCall.h
  3. **
  4. **    TurboTCP support library
  5. **    TCP resolver class
  6. **
  7. **    Copyright © 1993-94, FrostByte Design / Eric Scouten
  8. **
  9. */
  10.  
  11.  
  12. #pragma once
  13.  
  14. #include "TCL.h"
  15. #include <AddressXlation.h>
  16. #include <MacTCPCommonTypes.h>
  17.  
  18. #include "CTCPDriver.h"
  19. #include "CTCPEndpoint.h"
  20.  
  21. #ifndef TCL_NO_TEMPLATES
  22.     class CTCPResolverCallList;
  23. #else
  24.     class CPtrArray_CTCPResolverCall;
  25.     #define CTCPResolverCallList CPtrArray_CTCPResolverCall
  26. #endif
  27.  
  28.  
  29. // notification types for PostponeNotify()
  30.  
  31. enum NotifType {
  32.     notifNone,
  33.     notifStrToAddr,
  34.     notifAddrToName,
  35.     notifHInfo,
  36.     notifMXInfo
  37. };
  38.  
  39. typedef enum NotifType NotifType;
  40.  
  41.  
  42.  
  43. /*______________________________________________________________________
  44. **
  45. ** CTCPResolverCall
  46. **
  47. **    This class implements the core DNR calls. It is like the CTCPAsyncCall in that the call
  48. **    object is created to allow the call to persist beyond the scope of originating method.
  49. **    However, access to this object is not restricted; your application classes can and often
  50. **    will interact with the CTCPResolverCall object.
  51. **
  52. **    Each resolver object may support only one asynchronous resolver call at a time.
  53. **    You may create several resolver objects to simultaneously process several calls,
  54. **    so long as you respect MacTCP’s limit of 8 resolver calls open at once. The CTCPDriver
  55. **    acts as a referee to prohibit more than 8 simultaneous calls.
  56. **
  57. **    One set of methods (Do...) is called to initiate resolver calls. These are the methods you
  58. **    will typically call from your application classes. These methods initiate asynchronous
  59. **    calls to the DNR code resource. When the calls are completed, the notification is passed
  60. **    to another set of methods (Handle...). The Handle… methods return notification to your
  61. **    class through the Handle… methods in CTCPProtcolInterp. The exception to this is the
  62. **    DoAddrToStr method which returns the result immediately.
  63. **
  64. **    The userDataPtr fields of each of the calls are used by the resolver object to get
  65. **    notification of completion, and are not available to the caller.
  66. **
  67. **    The CTCPDriver object takes care of opening and closing the DNR code resource; it uses
  68. **    the OpenResolver and CloseResolver methods. You should not call these methods from your
  69. **    application classes.
  70. **
  71. **    The EnumCache call is not implemented in TurboTCP.
  72. **
  73. **    TurboTCP 1.0 NOTE: This class is no longer a descendant of CCollaborator. It now
  74. **    communicates only with the CTCPEndpoint mix-in class.
  75. **
  76. */
  77.  
  78. class CTCPResolverCall TCL_AUTO_DESTRUCT_OBJECT {
  79.  
  80.     friend class CTCPDriver;
  81.     friend class CTCPResolverList;
  82.     friend class UTurboTCP;
  83.  
  84.     #ifdef TCL_NO_TEMPLATES
  85.         friend class CPtrArray_CTCPResolverCall;
  86.     #endif
  87.  
  88.     TCL_DECLARE_CLASS;
  89.  
  90. private:
  91.     CTCPEndpoint*            itsEndpoint;            // endpoint object for this resolver
  92.     Boolean                inUse;                // resolver in use; can’t accept calls
  93.     Boolean                disposeOnCompletion;    // dispose of resolver call once completed
  94.     hostInfo                theHostInfo;            // parms for StrToAddr
  95.     returnRec                theHMXInfo;            // parms for HInfo or MXInfo
  96.     char                    hostName[255];        // name of user host
  97.     NotifType                pendingNotify;            // resolver is in ProcessNotify queue
  98.     static Handle            macDNRcode;            // the DNR code resource’s handle
  99.     static UniversalProcPtr    macDNRentry;            // the DNR code entry point
  100.     TurboTCPQElem            qEntry;                // completion queue entry
  101.  
  102. #if USESROUTINEDESCRIPTORS    
  103.     static ResultUPP        StrToAddrUPP;            // UPPs for all DNR callbacks
  104.     static ResultUPP        AddrToNameUPP;
  105.     static ResultProc2UPP    HInfoUPP;
  106.     static ResultProc2UPP    MXInfoUPP;
  107. #endif
  108.  
  109.  
  110.     // constructor/destructor
  111.  
  112. public:
  113.                     CTCPResolverCall(CTCPEndpoint& theEndpoint);
  114. private:
  115.     virtual            ~CTCPResolverCall();        // use Dispose() instead
  116. public:
  117.     void                Dispose();
  118.  
  119.  
  120.     // initiate resolver calls
  121.     
  122.     void                DoStrToAddr(char* theHostName);
  123.     static void        DoAddrToStr(ip_addr theIPaddr, char* theString);
  124.     void                DoAddrToName(ip_addr theIPaddr);
  125.     void                DoHInfo(char* theHostName);
  126.     void                DoMXInfo(char* theHostName);
  127.  
  128.  
  129.     // respond to completion of resolver calls
  130.  
  131. private:
  132.     void                ProcessNotify();
  133.     inline void            HandleStrToAddr()
  134.                         { if (itsEndpoint) itsEndpoint->HandleStrToAddr(&theHostInfo); }
  135.     inline void            HandleAddrToName()
  136.                         { if (itsEndpoint) itsEndpoint->HandleAddrToName(&theHostInfo); }
  137.     inline void            HandleHInfo()
  138.                         { if (itsEndpoint) itsEndpoint->HandleHInfo(&theHMXInfo); }
  139.     inline void            HandleMXInfo()
  140.                         { if (itsEndpoint) itsEndpoint->HandleMXInfo(&theHMXInfo); }
  141.  
  142.  
  143.     // open/close TCP resolver
  144.  
  145.     static void        OpenResolver();
  146.     static void        CloseResolver();
  147.     static short        OpenTheDNR();
  148.     static short        SearchFolderForDNRP(long targetType, long targetCreator, short vRefNum, long dirID);
  149.     static void        GetSystemFolder(short* vRefNumP, long* dirIDP);
  150.     static void        GetCPanelFolder(short* vRefNumP, long* dirIDP);
  151.  
  152.  
  153.     // interrupt-level methods: delay processing for non-interrupt status
  154.  
  155.     void                PostponeNotify(NotifType theNotifType);
  156.     static pascal void    PostponeStrToAddr(hostInfo* hostInfoPtr, char* userDataPtr);
  157.     static pascal void    PostponeAddrToName(hostInfo* hostInfoPtr, char* userDataPtr);
  158.     static pascal void    PostponeHInfo(returnRec* returnRecPtr, char* userDataPtr);
  159.     static pascal void    PostponeMXInfo(returnRec* returnRecPtr, char* userDataPtr);
  160.  
  161. };
  162.